package lol.oxguy3.droidpong;

import android.content.Context;

public class PongBall extends PongEntity {
	
	int radius;
	
	public PongBall(Context c, PongView v, int px, int py, int vx, int vy, int col) {
		this(c, v, px, py, vx, vy, col, 5);
	}
	
	public PongBall(Context c, PongView v, int px, int py, int vx, int vy, int col, int r) {
		super(c, v, px, py, vx, vy, col);
		radius = r;
	}
	
	@Override
	public void onMove() {
		super.onMove();
		
		
		if (posX-radius-10<0) {
			System.out.println("RIGHT WINS!");
			view.paddleRight.greatSuccess();
			return;
		}
		
		if (posX+radius+10>screenWidth) {
			System.out.println("LEFT WINS!");
			view.paddleLeft.greatSuccess();
			return;
		}
		
		if (posX-radius-20<=0&&posX-radius-10>=0) { /** potentially in the left paddle's hit box according to X coords */
			if (view.paddleLeft.getPosY() < posY && view.paddleLeft.getPosY()+view.paddleLeft.getHeight() > posY) {
				posX -= velX;
				posY -= velY;
				velX = -velX;
				System.out.println("left: yes!");
			} else {System.out.println("left: no!"); }
		}

		if (posX+radius+20>=screenWidth&&posX+radius+10<=screenWidth) { /** potentially in the right paddle's hit box according to X coords */
			if (view.paddleRight.getPosY() < posY && view.paddleRight.getPosY()+view.paddleRight.getHeight() > posY) {
				posX -= velX;
				posY -= velY;
				velX = -velX;
				System.out.println("right: yes!");
			} else {System.out.println("right: no!"); }
		}
		
		
		if (posY+radius>screenHeight) { /** bounces off bottom wall */
			posY -= velY;
			posX -= velX;
			velY = -velY;
		}
		
		if (posY-radius<0) { /** bounces off top wall */
			posY -= velY;
			posX -= velX;
			velY = -velY;
		}
		
		posX+=velX;
		posY+=velY;
	}
	
	public int getRadius() {
		return radius;
	}
	
	public void setRadius(int r) {
		radius = r;
	}
	
}
